unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, jpeg, ExtCtrls, DBCtrls, DB;

type
  Tfrmaddsetores = class(TForm)
    Image1: TImage;
    sb_confirmar: TSpeedButton;
    sb_cancelar: TSpeedButton;
    Label1: TLabel;
    Label2: TLabel;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    lb_setores: TDBLookupListBox;
    lb_setoresusu: TDBLookupListBox;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    procedure FormShow(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmaddsetores: Tfrmaddsetores;
  setor:string;
  n : integer;

implementation

uses Unit2, Unit8;

{$R *.dfm}

procedure Tfrmaddsetores.FormShow(Sender: TObject);

begin
if strtoint(frmusuarios.ed_codigo.Text) <= dmbanco.tb_usuarios.RecordCount then
begin
  frmusuarios.ed_codigo.ReadOnly := false;
  dmbanco.qrySetorPermicao.Close;
  dmbanco.qrySetorPermicao.Parameters.Items[0].Value := strtoint(frmusuarios.ed_codigo.Text);
  dmbanco.qrySetorPermicao.Open;

  dmbanco.qryPermicaoUsuario.Close;
  dmbanco.qryPermicaoUsuario.Parameters.Items[0].Value := strtoint(frmusuarios.ed_codigo.Text);
  dmbanco.qryPermicaoUsuario.Open;
  frmusuarios.ed_codigo.ReadOnly := true;
  end;
end;

procedure Tfrmaddsetores.SpeedButton4Click(Sender: TObject);
begin
frmusuarios.ed_codigo.ReadOnly := false;
dmbanco.gravaPermicao(StrToInt(frmusuarios.ed_codigo.Text), lb_setoresusu.KeyValue);
FormShow(Self);
frmusuarios.ed_codigo.ReadOnly := true;
end;

end.
